package com.atguigu.gmall_logger.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by RUI on 2021/6/23 10:55
 */
@Slf4j
@RestController
public class LoggerController {

    @Autowired
    KafkaTemplate<String,String> kafka;

    @RequestMapping("/applog")
    public String doLog(@RequestParam("param") String logStr){

        write2File(logStr);
        send2Kafka(logStr);

        return "ok";
    }

    private void send2Kafka(String logStr) {
        kafka.send("ods_log", logStr);
    }

    private void write2File(String logStr) {
        log.info(logStr);
    }
}
